package com.cyh.core.framework.common.constant;

import org.springframework.stereotype.Component;


import java.io.File;
import java.lang.reflect.Field;

@Component
public class FileConstant {

    public static final String ROOT_PATH = ".";
    public static final String FILE_PATH = "./files";
    public static final String UPLOAD_FILE_PATH = FILE_PATH+"/UpLoadFiles";
    public static final String RESOURCE_PATH = "./src/main/resources";

    // SYSTEM
    public static final String SYSTEM_USER_HOME = System.getProperty("user.home");
    public static final String SYSTEM_USER_DESKTO = SYSTEM_USER_HOME+"/desktop";
    public static final String SYSTEM_USER_DIR = System.getProperty("user.dir");

    static {

        try {
            System.out.println("初始化文件目录");
            Field[] fields = FileConstant.class.getDeclaredFields();
            for (Field f:fields) {
                if ("RESOURCE_PATH".equals(f.getName()) ||
                        "SYSTEM_USER_HOME".equals(f.getName()) ||
                        "SYSTEM_USER_DIR".equals(f.getName()) ||
                        "SYSTEM_USER_DESKTO".equals(f.getName())){
                    continue;
                }
                File file=new File((String) f.get(f.getName()));
                System.out.println(file.getCanonicalPath());
                if (!file.exists()){
                    file.mkdir();
                }
            }
        }catch (Exception e){
            throw new RuntimeException(e.getMessage());
        }

    }

}
